/*
 * Created on 2005-4-17
 *
 */
package com.nauu.atombuilder.commands;

import java.util.Iterator;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;

import com.nauu.atombuilder.modle.Guide;
import com.nauu.atombuilder.modle.Node;

/**
 * @author Administrator
 *
 */
public class MoveGuideCommand extends Command {

    private Guide guide;

    private int delta;

    /**
     * @param guide
     * @param delta
     */
    public MoveGuideCommand(Guide guide, int delta) {
        setLabel("Move Guide");
        this.guide = guide;
        this.delta = delta;
    }

    public void execute() {
        guide.setPosition(guide.getPosition() + delta);
        Iterator iter = guide.getMap().keySet().iterator();
        while (iter.hasNext()) {
            Node node = (Node) iter.next();
            Point location = node.getLocation().getCopy();
            if (guide.isHorizontal()) {
                location.y += delta;
            } else {
                location.x += delta;
            }
            node.setLocation(location);
        }
    }

    public void undo() {
        guide.setPosition(guide.getPosition() - delta);
        Iterator iter = guide.getMap().keySet().iterator();
        while (iter.hasNext()) {
            Node node = (Node) iter.next();
            Point location = node.getLocation().getCopy();
            if (guide.isHorizontal()) {
                location.y -= delta;
            } else {
                location.x -= delta;
            }
            node.setLocation(location);
        }
    }

}
